//
//  SCSubmitOrder_EPController.m
//  shangcheng
//
//  Created by 张艳江 on 2019/7/1.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCSubmitOrder_EPController.h"
#import "SCPaySuccess_EPController.h"

@interface SCSubmitOrder_EPController ()

@property (weak, nonatomic) IBOutlet UIImageView *goodsImage;
@property (weak, nonatomic) IBOutlet UILabel     *nameLab;
@property (weak, nonatomic) IBOutlet UILabel     *refundTypeLab;
@property (weak, nonatomic) IBOutlet UILabel     *numLab;
@property (weak, nonatomic) IBOutlet UILabel     *priceLab;
@property (weak, nonatomic) IBOutlet UILabel     *totalPriceLab;
@property (weak, nonatomic) IBOutlet UIView      *bgView;
@property (weak, nonatomic) IBOutlet UILabel     *phoneLab;

@property (assign, nonatomic) int count;

@end

@implementation SCSubmitOrder_EPController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //设置数据
    self.bgView.layer.cornerRadius = 2.0;
    self.bgView.layer.borderColor = RGB(239, 239, 239).CGColor;
    self.bgView.layer.borderWidth = 0.6f;
    self.numLab.layer.borderColor = RGB(239, 239, 239).CGColor;
    self.numLab.layer.borderWidth = 0.6f;
    
    self.count = 1;
    self.totalPriceLab.text = [NSString stringWithFormat:@"¥ %@",self.model.price];
    
    [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.douyinhot.com/upload/foodshop_goods/%@",self.model.image]] placeholderImage:[UIImage imageNamed:@""]];
    self.refundTypeLab.text = self.model.rule;
    self.nameLab.text = self.model.name;
    self.priceLab.text = [NSString stringWithFormat:@"¥ %@",[MyTool removeFloatAllZeroByString:self.model.price]];
    self.phoneLab.text = Phone;
}
#pragma mark - 加减
- (IBAction)clickAddOrSubBtn:(UIButton *)sender {
    if (sender.tag == 0) {//加
        self.count++;
    }else{
        if (self.count == 1) {
            [SVProgressHUD showImage:nil status:@"已减至最小购买数量"];
        }else{
            self.count--;
        }
    }
    self.numLab.text = [NSString stringWithFormat:@"%d",self.count];
    
    NSString *total = [CGPriceTool decimalNumberCalucate:self.numLab.text originValue2:self.model.price calucateWay:Multiplying];
    self.totalPriceLab.text = [NSString stringWithFormat:@"¥ %@",total];
}
#pragma mark - 提交订单
- (IBAction)clickSubmitBtn:(UIButton *)sender {
    
    
    NSString *url = [MyTool splicingWithUrl:@"admin.php?g=System&c=EdphApp&a=Order_submission"];
    NSDictionary *dict = @{@"token":Token,
                           @"food_id":self.model.goods_id,
                           @"foods_num":self.numLab.text,
                           @"pay_method":@"1",
                           @"pay_mac":@"1",
                           @"order_from":@"0",
                           @"from_plat":@"0"};
    [SVProgressHUD showWithStatus:@"提交中..."];
    [[NetworkRequestTool sharedNetworkTool] POST:url parameters:dict finished:^(id result, NSString *error) {
        [SVProgressHUD dismiss];
        //NSLog(@"提交订单返回的数据:%@",result);
        SCPaySuccess_EPController *vc = [[SCPaySuccess_EPController alloc]init];
        vc.title = self.title;
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

@end
